<template>
  {{ datas }}
  <el-form ref="ruleFormRef" style="max-width: 600px" :model="Addinfo" :rules="rules" label-width="auto"
    class="demo-ruleForm" :size="formSize" status-icon>

    <el-form-item label="栏位名称" prop="columnName">
      <el-input v-model="Addinfo.columnName" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormRef)">
        添加
      </el-button>

    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>


import starts from "@/api/EarTagManagement/index";
import vendor from "@/api/OrganizationalAdministration/index";
import { AddColumn } from "@/api/OrganizationalAdministration/index";
import { Rideg } from "@/api/OrganizationalAdministration/index";
import axios from "axios";
import { number } from "echarts";
import { useRouter, useRoute } from "vue-router";
const useRoutes = useRouter()
const useRoutea = useRoute()

console.log(useRoutea.query.ridgepoleId)

const formSize = ref('default')
const ruleFormRef = ref()

const Addinfo = reactive<AddColumn>({
  columnName: "",
  ridgepoleId: useRoutea.query.ridgepoleId
})



const rules = reactive({
  columnName: [
    { required: true, message: '栏位名称不能为空', trigger: 'blur' },

  ]
})



const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      vendor.AddinfosCol(Addinfo).then(res => {
        if (res.data > 0) {
          ElMessage.success("添加成功");
          useRoutes.push({
            path:'/ColumnListShow',
            query: {
              ridgepoleId: useRoutea.query.ridgepoleId
            }
          
          
          })
        }

      })
    } else {
      console.log('error submit!', fields)
    }
  })
}



</script>